use ndarray::{array, Array2};
use rstest::rstest;

use crate::tests::fixtures::{
    rand_usize,
    random_border_tile_id,
    random_coordinates,
    random_last_leaves,
    random_missing_tile_policy,
    random_predecessor,
    random_tile_selection_policy,
    random_vacancy_policy,
    random_tiles
};
use crate::tiling::slot_grid::tests::create_reproducible_grid_slot_with_tile_id;
use crate::tiling::tiles::tile_list::TileList;
use crate::tiling::tiles::{ArrayInitializable, Tile, TileConnectionArray, TileType};
use crate::tiling::{GridSlot, SlotGrid};

#[rstest]
#[case::none_1_1(
    array![
        [create_reproducible_grid_slot_with_tile_id(None)]
    ],
    random_tiles(rand_usize(0, 256)),
    " ",
)]
fn test_output_text(
    #[case] grid: Array2<Option<GridSlot>>,
    #[case] tiles: Vec<Tile>,
    #[case] expected_result: &str,
) {
    let tile_list = TileList {
        tiles,
        horizontal_connector_names: vec![],
        vertical_connector_names: vec![],
        tile_type: TileType::Text,
    };

    let slot_grid = SlotGrid {
        num_rows: grid.nrows() - 1,
        num_cols: grid.ncols() - 1,
        grid,
        border_tile_id: random_border_tile_id(),
        tile_connections: TileConnectionArray::new(&tile_list.tiles),
        tile_list,
        missing_tile_policy: random_missing_tile_policy(),
        tile_selection_policy: random_tile_selection_policy(),
        vacancy_policy: random_vacancy_policy(),
        current_slot: random_coordinates(),
        current_predecessor: random_predecessor(),
        last_leaves: random_last_leaves(),
        exposed_edge_count: rand_usize(1, 15),
    };

    let result = slot_grid.output_text();

    assert_eq!(result, expected_result);
}
